PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Commands and Objects

Commands are the words or phrases you use in AppleScript statements to request actions or results. Every command is directed at a target, which is the object that responds to the command. The target of a command is usually an application object. Application objects are objects that belong to an application, such as windows, or objects in documents, such as the words and paragraphs in a text document. Commands can also be targeted at system objects , which specify objects that belong to the Mac OS, such as a desktop printer, a user or group object from the Users & Groups control panel, or a theme object from the Appearance control panel.

Each application or system object has specific information associated with it and can respond to specific commands.

For example, in the Finder, window objects understand the Close command. The following example shows how to use the Close command to request that the Finder close the front window.

tell application "Finder"
    close the front window
end tell

The Close command is contained within a Tell statement. Tell statements specify default targets for the commands they contain. The default target is the object that receives commands if no other object is specified or if the object is specified incompletely in the command. In this case, the statement containing the Close statement does not contain enough information to uniquely identify the window object, so AppleScript uses the application name listed in the Tell statement to determine which object receives the Close command.

In AppleScript, you use references to identify objects. A reference is a compound name, similar to a pathname or address, that specifies an object. For example, the following phrase is a reference:

front window of application "Finder"

This phrase specifies a window object that belongs to a specific application. (The application itself is also an object.) AppleScript has different types of references that allow you to specify objects in many different ways. You'll learn more about references in Objects and References

Objects can contain other objects, called elements. In the previous example, the front window is an element of the Finder application object. Similarly, in the next example, a file element is contained in a specific folder element, which is contained in a specific disk. You can read more about references to Finder objects in Objects and References

file 1 of folder 1 of startup disk

Every object belongs to an object class, which is simply a name for objects with similar characteristics. Among the characteristics that are the same for the objects in a class are the commands that can act on the objects and the elements they can contain. An example of an object class is the Folder object class in the Finder. Every folder visible in the Finder belongs to the Folder object class. The Finder's definition of the Folder object class determines which classes of elements, such as files and folders, a folder object can contain. The definition also determines which commands, such as the Close command, a folder object can respond to.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)